package i5.modelman.merge.dependency;

import i5.modelman.chase.ParsingException;
import i5.modelman.chase.PrologUtil;

import java.io.IOException;

import jpl.Query;
import jpl.Term;

/**
 * A constraint is a rule in a mapping. It can be unidirectional or bidirectional. If both sides 
 * of the constraint belong to one model then the constraint is interpreted as an integrity constraint.
 * If each side belong to a distinct model, then it is interpreted as a mapping constraint.
 *  
 * 
 * @author lixiang
 *
 */
public class ConstraintImpl implements Constraint {
	private Query lhs;
	private Query rhs;
	private ImplicationDirection direction;	
	
	
	
	ConstraintImpl(Query leftQuery, Query rightQuery,
			ImplicationDirection direction) {
		this.lhs = leftQuery;
		this.rhs = rightQuery;
		this.direction = direction;
	}
	
	/* (non-Javadoc)
	 * @see i5.modelman.merge.mapping.IConstraint#getLhs()
	 */
	public Query getLhs() {
		return lhs;
	}
	/* (non-Javadoc)
	 * @see i5.modelman.merge.mapping.IConstraint#getRhs()
	 */
	public Query getRhs() {
		return rhs;
	}
	/* (non-Javadoc)
	 * @see i5.modelman.merge.mapping.IConstraint#getDirection()
	 */
	public ImplicationDirection getDirection() {
		return direction;
	}
	
	
	
//	public static void main(String... args) throws IOException, ParsingException{
////        System.out.println("Enter input string to parse: ");
////        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//		String line = "go_flight(Fnum, Time, Meal), go_price(Fnum, Date, Price), abc(X)<->ok_flight(Fnum, Date, Time, Price, Nonstop).";
//		Constraint c = ConstraintFactory.createFromString(line);
//		System.out.println(c);
//		System.out.println(PrologUtil.constraintToFlattenedString(c));
//	}	
//	
	public String toString(){
		return getLhs().toString() + direction + getRhs().toString();
	}
	
}
